﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using ServerBase.LunarSocket;
using ServerBase.Protocol;
using UtilLib;
using static ServerBase.Config.Conf;
using static ServerBase.Service.BaseDispatch;
using static UtilPublic.Redis.ServerRedis;
using ServerGame.Service;
using System.Collections.Generic;
using UtilPublic.ServerLoger;
using ServerBase.Service;
using ServerBase.Config;
using static ServerGame.Service.Dispatcher;
using ServerBase.Client;
using System;
using ServerPublic.Data;
using ServerGame.GameObject;
using static UtilPublic.Serialization.Jsh;
using ServerPublic.DataBaseMysql;
using UtilPublic.ApiDispatcher;
using ServerGame.Data;
using System.Text;
using System.Linq;

namespace ServerGame.Manager
{
    /// <summary>
    /// 管理 Efun
    /// </summary>
    public static partial class Efun
    {
        public static string DescLevel(int value)
        {
            var lv = Math.Clamp(value, ConfDescLevel.Keys.Min(), ConfDescLevel.Keys.Max());
            return ConfDescLevel[lv].ColorName();
        }
        public static string DescDamage(int value)
        {
            var lv = Math.Clamp(value / 25, ConfDescDamage.Keys.Min(), ConfDescDamage.Keys.Max());
            return ConfDescDamage[lv].Desc;
        }
        public static string DescKee(int value, int max)
        {
            var pct = 0;
            if (max > 0)
            {
                pct = value * 100 / max;
            }
            pct = Math.Clamp(pct, 0, 100);
            foreach (var item in ConfCbtKee.Values)
            {
                if (pct >= item.Vmin && pct < item.Vmax)
                {
                    return item.Desc;
                }
            }
            return ConfCbtKee.Values.First().Desc;
        }
        public static string DescEfKee(int value, int max)
        {
            var pct = 0;
            if (max > 0)
            {
                pct = value * 100 / max;
            }
            pct = Math.Clamp(pct, 0, 100);
            foreach (var item in ConfCbtEfKee.Values)
            {
                if (pct >= item.Vmin && pct < item.Vmax)
                {
                    return item.Desc;
                }
            }
            return ConfCbtEfKee.Values.First().Desc;
        }
        public static string DescSen(int value, int max)
        {
            var pct = 0;
            if (max > 0)
            {
                pct = value * 100 / max;
            }
            pct = Math.Clamp(pct, 0, 100);
            foreach (var item in ConfCbtSen.Values)
            {
                if (pct >= item.Vmin && pct < item.Vmax)
                {
                    return item.Desc;
                }
            }
            return ConfCbtSen.Values.First().Desc;
        }
        public static string DescPer(int age, string gender, int per)
        {
            if (age < 14)
            {
                var perlv = Math.Clamp((per - 10) / 5, ConfDescPer1.Keys.Min(), ConfDescPer1.Keys.Max());
                return ConfDescPer1[perlv].Desc.RandomSingle();
            }
            else
            {
                if (gender == "女性")
                {
                    var perlv = Math.Clamp(per, ConfDescPer3.Keys.Min(), ConfDescPer3.Keys.Max());
                    return ConfDescPer3[perlv].Desc;
                }
                else
                {
                    var perlv = Math.Clamp(per, ConfDescPer2.Keys.Min(), ConfDescPer2.Keys.Max());
                    return ConfDescPer2[perlv].Desc;
                }
            }
        }

    }
}
